<?php
/**
 * A upload base system
 * @author Can.Nguyen
 */
class CMS_Upload
{

    public static function uploadProductImages(Zend_Form_Element_File $file)
    {
        if (! $file->isUploaded ())
            return null;
        
        $uid = md5(Zend_Date::now ()->toValue () . rand(0,1000));
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/products/" . $uid . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        
        // create thumbnail
        //$thumb = CMS_PhpThumb_PhpThumbFactory::create("public/data/products/" . $uid . "." . $fileInfo ['extension']);  
		//$thumb->adaptiveResize(150, 150)->save("public/data/products/" . $uid . "_thumb." . $fileInfo ['extension']);  
        
        return $file->getFileName ( null, false );
    }
}